package net.mingsoft.basic.util;

import agw.service.gm.client.GMServiceClient;
import agw.service.gm.client.VerifySDReqI;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class AGWUtils {
    private static String AGWURL_DEV = "http://59.50.99.128:7171/AGW/services/GMService?wsdl";

    private static String AGWURL_PRO1 = "http://59.212.139.36:8080/AGW/services/GMService?wsdl";
    private static String AGWURL_PRO2 = "http://59.212.139.37:8080/AGW/services/GMService?wsdl";

    private static String APP_ID_DEV = "GDCATest";

    private static String APP_ID_PROD = "WANGXINDASHUJU";

    public static String CERT_CHECK = "CertCheck";

    public static String VERIFY_SIGN = "VerifySign";

    private static String PROD = "prod";

    public void verifySignedData(VerifySDReqI verifySDReqI) {
        log.info("AGWUtils|verifySignedData  Start|verifySDReqI = {}", JSONObject.toJSON(verifySDReqI));
        verifySDReqI.setAppID(getAppid());
    }

    public static GMServiceClient getClient() {
        String agurl = getAgurl();
        try {
            return new GMServiceClient(agurl);
        } catch (Exception e) {
            log.error("AGWUtils|getClient|获取连接失败");
        }
        throw new RuntimeException("获取签名连接失败，请稍后重试");
    }



    public static String getAgurl() {
        return PROD.equals(getProfile()) ? AGWURL_PRO1 : AGWURL_DEV;
    }

    public static String getAppid() {
        return PROD.equals(getProfile()) ? APP_ID_PROD : APP_ID_DEV;
    }

    public static String getProfile() {
        try {
            return ApplicationContextUtil.getApplicationContext().getEnvironment().getProperty("spring.profiles.active");
        } catch (Exception e) {
            return "";
        }
    }

}
